package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NursingLevelServiceImpl implements NursingLevelService {
    @Autowired
    private NursingLevelMapper nursingLevelMapper;

    /**
     * 分页查询护理等级
     *
     * @param name     护理等级名称
     * @param status   护理等级状态
     * @param pageNum  当前页码
     * @param pageSize 显示数据条数
     * @return
     */
    @Override
    public PageResponse<NursingLevelVo> getByPage(String name, Integer status, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);

        Page<NursingLevelVo> page = nursingLevelMapper.getByPage(name,status);
        PageResponse<NursingLevelVo> pageResponse = new PageResponse<>(page);
        pageResponse.setRecords(page.getResult());
        return pageResponse;
    }

    /**
     * 添加护理等级
     *
     * @param nursingLevelDto 护理等级信息
     * @return
     */
    @Override
    public void addLevel(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = new NursingLevel();
        BeanUtil.copyProperties(nursingLevelDto,nursingLevel);
        nursingLevelMapper.addLevel(nursingLevel);
    }

    /**
     * 删除护理等级
     *
     * @param id 护理等级id
     * @return
     */
    @Override
    public void deleteLevel(Long id) {
        nursingLevelMapper.deleteLevel(id);

    }

    /**
     * 根据id查询护理等级信息
     *
     * @param id 护理等级id
     * @return
     */
    @Override
    public NursingLevelVo getLevelById(Long id) {
        NursingLevelVo nursingLevelVo = nursingLevelMapper.getLevelById(id);
        return nursingLevelVo;
    }

    /**
     * 修改护理等级信息
     *
     * @param nursingLevelDto
     * @return
     */
    @Override
    public void updateLevel(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = new NursingLevel();
        BeanUtil.copyProperties(nursingLevelDto,nursingLevel);
        nursingLevelMapper.updateLevel(nursingLevel);
    }

    /**
     * 查询所有护理等级
     *
     * @return
     */
    @Override
    public List<NursingLevelVo> getAllLevel() {
        List<NursingLevelVo> nursingLevelVos = nursingLevelMapper.getAllLevel();
        return nursingLevelVos;
    }

    /**
     * 修改护理等级状态
     *
     * @param id     护理等级id
     * @param status 护理等级状态
     * @return
     */
    @Override
    public void updateStatus(Long id, Integer status) {
        nursingLevelMapper.updateStatus(id,status);
    }
}
